
import java.io.*;
import java.net.*;
import java.util.*;

import javax.swing.Icon;
import javax.swing.ImageIcon;


public class AltaVistaSearchWorker extends SearchWorker
{
    private final static String template = 
	    "<dl>"
	+  " <dt>" 
	+    " <b>@(any)</b>"
	+    " <a href=\"@(any=url)\">"
	+      " <b>@(any=title)</b>"
	+    " </a>"
	+  " </dt>"
	+  " <dd>@(any=text)</dd>"
	+  " @(any)Last modified on: @(any=date)"
	+  " @(any)"
	+ "</dl>";

    private final static PageParser parser = new PageParser(template);

    private final static Icon icon = new ImageIcon("images/altavista.gif");


    public AltaVistaSearchWorker(Search search, String query) {
	super(search, query);
    }

    protected PageParser getPageParser() {
	return parser;
    }

    /**
     * This URL approximates an AltaVista query for keyword q, page t.
     * AltaVista puts up to 10 hits on each page and a query like "swing"
     * returns about a million hits however the search engine will only 
     * report the first 200.
     */
    protected URL getPageURL(String q, int t) throws MalformedURLException {
	String queryURLString = 
	    "http://www.altavista.com/cgi-bin/query?pg=q&stype=stext&sc=on&q=" + q + "&stq=" + t;
	return new URL(queryURLString);
    }

    public String getSiteName() {
	return "AltaVista";
    }

    public Icon getSiteIcon() {
	return icon;
    }
}
